package com.rc.saas.tenant.service.ugs;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.BaseSearch;
import com.rc.saas.tenant.common.vo.TResponse;
import com.rc.saas.tenant.mapper.ugs.TenantUgsLevelGrowingMapper;
import com.rc.saas.tenant.model.ugs.TenantUgsLevelGrowing;
import com.rc.saas.tenant.model.ugs.TenantUgsLevelGrowingExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author frog
 * @date 2021/4/3
 */
@Service
public class TenantUgsLevelGrowingServiceImpl implements TenantUgsLevelGrowingService {

    @Autowired
    private TenantUgsLevelGrowingMapper tenantUgsLevelGrowingMapper;

    @Override
    public TenantUgsLevelGrowingMapper getMapper() {
        return tenantUgsLevelGrowingMapper;
    }

    @Override
    public PageInfo<TenantUgsLevelGrowing> listPageTenantUgsLevelGrowing(BaseSearch search) {
        PageHelper.startPage(search.getOffset(), search.getLimit());
        TenantUgsLevelGrowingExample example = new TenantUgsLevelGrowingExample();
        example.createCriteria().andTenantCodeEqualTo(search.getTenantCode());
        List<TenantUgsLevelGrowing> tenantUgsLevelGrowings = tenantUgsLevelGrowingMapper.selectByExample(example);
        return new PageInfo<TenantUgsLevelGrowing>(tenantUgsLevelGrowings);
    }

    @Override
    public TResponse updateStatus(Long levelGrowingId) {
        TenantUgsLevelGrowing tenantUgsLevelGrowing = tenantUgsLevelGrowingMapper.selectByPrimaryKey(levelGrowingId);
        if ("0".equals(tenantUgsLevelGrowing.getStatus())) {
            tenantUgsLevelGrowing.setStatus("1");
        } else if ("1".equals(tenantUgsLevelGrowing.getStatus())) {
            tenantUgsLevelGrowing.setStatus("0");
        }
        tenantUgsLevelGrowingMapper.updateByPrimaryKeySelective(tenantUgsLevelGrowing);
        return TResponse.SUCCESS();
    }
}
